//
//  HomeViewController.m
//  PeopleStreet
//
//  Created by 喻飞 on 15/12/24.
//  Copyright © 2015年 yuf. All rights reserved.
//

#import "HomeViewController.h"
#import "ShopViewController.h"
#import "GroupShoppingDetailViewController.h"
#import "ShoppingProductDetailViewController.h"
#import "UIImageView+WebCache.h"
#import <UIImageView+RJLoader.h>
#import "RecommendCollectionViewCell.h"
#import "HotRecommentCollectionViewCell.h"
#import "HotGroupShopCollectionViewCell.h"
#import "WebDetailInfoViewController.h"
#import "IndoorMapViewController.h"
static NSString * bandsCellIdentifer = @"RecommendCollectionViewCell";
static NSString * hotCellIdentifer = @"HotRecommentCollectionViewCell";
static NSString * hotGroupCellIdentifer = @"HotGroupShopCollectionViewCell";
@interface HomeViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,DYQBannerScrollViewDelegate>
/*****/
@property (strong,nonatomic) DYQBannerScrollView *bannerScrollView;//广告栏
@property(nonatomic,strong)NSMutableArray * bannerArray;
@property (nonatomic,strong)  NSMutableArray  *imageArray;
@property (strong, nonatomic) IBOutlet UICollectionView *hotGroupShopCollection;
@property (strong, nonatomic) IBOutlet UILabel *noticeNumber;
@property(nonatomic,strong)NSMutableArray * brandSellingArray;//猜你喜欢商品
@property(nonatomic,strong)NSMutableArray * productGroupPurchase;//热门团购
@property(nonatomic,strong)NSMutableArray * neGoodsRecommend;
@property (strong, nonatomic) IBOutlet UIPageControl *pageController;
@property(nonatomic,assign)NSInteger currentIndenx;
@end

@implementation HomeViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if([Common getLoginStatus]){
        [self getNoticeNumber];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //    [self getAdvertiseBanner];
    [self initViewLayout];
    self.imageArray = [NSMutableArray array];
    _bannerArray = [NSMutableArray array];
    _neGoodsRecommend = [NSMutableArray array];
    _brandSellingArray = [NSMutableArray array];
    _productGroupPurchase = [NSMutableArray array];
    [self addRefreshing];
    //加载数据
    [self getAdvertiseBanner];
//    [self getGoodsList];
    //品牌热卖
    [self queryBrandSellingData];
    //热门团购
//    [self queryAppPopularGroupPurchase];
    
}
#pragma mark  布局调整--=========================================
- (void)initViewLayout{
    
    //功能栏
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navgationView];
    [self adaptiveViewLayout:self.mainScroll];
    self.mainScroll.frame = CGRectMake(0, 64*VerticalRatio(),320*VerticalRatio(), 504*VerticalRatio()-49);
    [self adaptiveViewLayout:self.funtionView];
    [self adaptiveViewLayout:self.functionTwoView];
    [self adaptiveViewLayout:self.funtionOneView];
    self.mainScroll.contentSize = CGSizeMake(1, 495*VerticalRatio());
    
    
    self.noticeNumber.layer.masksToBounds = YES;
    self.noticeNumber.layer.cornerRadius = 6*VerticalRatio();
    //广告栏
    self.bannerScrollView = [[DYQBannerScrollView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 140), NO)];
    [self.mainScroll addSubview:self.bannerScrollView];
    self.bannerScrollView.backgroundColor = [UIColor clearColor];
    self.bannerScrollView.pageControlPosition = PageControlPositionCenter;
    self.bannerScrollView.noDataPlaceholderImage = [UIImage imageNamed:@"cover_cy"];
    self.bannerScrollView.timeInterval = 3;
    self.bannerScrollView.pageControllerTintColor = [UIColor whiteColor];
    self.bannerScrollView.pageControllerCurrentColor = [UIColor orangeColor];


    
    UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.minimumInteritemSpacing = 1*VerticalRatio();
    flowLayout.minimumLineSpacing = 1*VerticalRatio();
    self.recommendBandsCollection.collectionViewLayout = flowLayout;
    self.recommendBandsCollection.userInteractionEnabled=YES;
    _recommendBandsCollection.delegate = self;
    _recommendBandsCollection.dataSource = self;
    [self.recommendBandsCollection registerNib:[UINib nibWithNibName:bandsCellIdentifer bundle:nil] forCellWithReuseIdentifier:bandsCellIdentifer];
    
    
    UICollectionViewFlowLayout *FlowLayout =[[UICollectionViewFlowLayout alloc]init];
    FlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    FlowLayout.minimumInteritemSpacing = 1*VerticalRatio();
     FlowLayout.minimumLineSpacing = 1*VerticalRatio();
    self.hotRecommendCollection.collectionViewLayout = FlowLayout;
    self.hotRecommendCollection.userInteractionEnabled=YES;
    _hotRecommendCollection.delegate = self;
    _hotRecommendCollection.dataSource = self;
    _hotRecommendCollection.pagingEnabled = YES;
    [self.hotRecommendCollection registerNib:[UINib nibWithNibName:hotCellIdentifer bundle:nil] forCellWithReuseIdentifier:hotCellIdentifer];
    
    
    UICollectionViewFlowLayout *hFlowLayout =[[UICollectionViewFlowLayout alloc]init];
    hFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    hFlowLayout.minimumInteritemSpacing = 0;
    hFlowLayout.minimumLineSpacing = 4*VerticalRatio();
    self.hotGroupShopCollection.collectionViewLayout = hFlowLayout;
    self.hotGroupShopCollection.userInteractionEnabled=YES;
    _hotGroupShopCollection.delegate = self;
    _hotGroupShopCollection.dataSource = self;
    [self.hotGroupShopCollection registerNib:[UINib nibWithNibName:hotGroupCellIdentifer bundle:nil] forCellWithReuseIdentifier:hotGroupCellIdentifer];
    
   
}
#pragma mark -- 添加刷新数据
- (void)addRefreshing{
    self.mainScroll.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        int64_t delayInSeconds = 8.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [self.mainScroll.header endRefreshing];
        });
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [self getAdvertiseBanner];
            [self getGoodsList];
            //品牌热卖
            [self queryBrandSellingData];
            //热门团购
            [self queryAppPopularGroupPurchase];
        });
    }];
    // 马上进入刷新状态
//    [self.mainScroll.header beginRefreshing];
}
#pragma mark  ====== 便民服务
- (IBAction)checkShoppingInfoPage:(UIButton *)sender {
   
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Convenience"];
    [self.navigationController   pushViewController:page animated:YES];

}
#pragma mark == 美食
- (IBAction)checkFoodPage:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"FoodsHome"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark == 智能车库
- (IBAction)winesShop:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"IntelligentGarage"];
    [self.navigationController   pushViewController:page animated:YES];
   }
#pragma mark == 商圈导航
- (IBAction)conductHandel:(id)sender {
    
//    CGFloat timef = 0.2;
//    //主要是转屏之后view的再次旋转
//    if ( [[[UIDevice currentDevice] systemVersion] floatValue]>8|| [[[UIDevice currentDevice] systemVersion] floatValue]<8.4) {
////        self.view.hidden = YES;
//        [self viewWillDisappear:NO];
//        timef = 0.1;
//    }
//    dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, timef*NSEC_PER_SEC);
//    dispatch_after(time, dispatch_get_main_queue(), ^{
//        dispatch_async(dispatch_get_main_queue(), ^(){
            //跳转界面
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"MapStoryboard" bundle:nil];
            IndoorMapViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"IndoorMapView"];
            [self.navigationController   pushViewController:page animated:YES];
//        });
//    });
    
   
}
#pragma mark == 酒店预订
- (IBAction)happyHandel:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Hotels"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark == 智慧商城
- (IBAction)stopCar:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingHome"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark == 影院
- (IBAction)filmCenter:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Film"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark == 智慧物业
- (IBAction)brandsHandel:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"property"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark == 活动
- (IBAction)activityHandel:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ActivityCenter"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark == 农超对接
- (IBAction)groupShop:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"FarmSupermarketStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"FarmSupermarket"];
    [self.navigationController   pushViewController:page animated:YES];

}
#pragma mark == 消息中心
- (IBAction)noticeCenter:(id)sender {
    if (![Common getLoginStatus]) {
        [self ShowLoginPage];
        return;
    }
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"PersonCenterStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"NoticeCenter"];
    [self.navigationController   pushViewController:page animated:YES];
}


#pragma mark -- 新品推荐
- (void)getGoodsList{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic  setObject:[NSNumber numberWithInteger:1]     forKey:@"currentPage"];
    [dic  setObject:[NSNumber numberWithInteger:PageSize]       forKey:@"pageSize"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_GetGoodsLists withHttpType:@"POST" withTag:SX_GetGoodsList];
    
}


#pragma mark == 品牌热卖
- (void)queryBrandSellingData{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"" forKey:@"storeType"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_QueryMallBrandDataData withHttpType:@"POST" withTag:SX_QueryMallBrandDataDataTag];
}
#pragma mark == 热门团购
- (void)queryAppPopularGroupPurchase{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_queryAppPopularGroupPurchase withHttpType:@"POST" withTag:SX_queryAppPopularGroupPurchaseTag];
}
#pragma mark === 获取消息条数
- (void)getNoticeNumber{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_queryfincationCount withHttpType:@"POST" withTag:SX_SX_queryfincationCount];
}

#pragma mark == 搜索
- (IBAction)GosearchHandel:(id)sender {
    
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Search"];
    [self.navigationController   pushViewController:page animated:YES];
    
    
}

#pragma mark  获取首页广告BANNER--=========================================
-(void)getAdvertiseBanner{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"queryMallADDData" forKey:@"method"];
    [dic setObject:@"1" forKey:@"position"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_ADBanner withHttpType:@"POST" withTag:SX_kADBannerTag];
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView == _hotRecommendCollection) {
        
        _currentIndenx = (_hotRecommendCollection.contentOffset.x - _hotRecommendCollection.frame.size.width/2)/_hotRecommendCollection.frame.size.width + 1;
        _pageController.currentPage = _currentIndenx;
    }
    
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (scrollView == _hotRecommendCollection) {
        [_hotRecommendCollection setContentOffset:CGPointMake(_hotRecommendCollection.frame.size.width * _currentIndenx,_hotRecommendCollection.contentOffset.y) animated:YES]; //设置scrollview的显示为当前滑动到的页面
        
    }
}

#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if ([collectionView isEqual:self.recommendBandsCollection]) {
        return _brandSellingArray.count;
    }else if([collectionView isEqual:self.hotGroupShopCollection]){
        return _productGroupPurchase.count;
    }else{
        return _neGoodsRecommend.count;
    }
    
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.recommendBandsCollection]) {
        return CGSizeMake(78*VerticalRatio(), 35*VerticalRatio());
    }else if([collectionView isEqual:self.hotGroupShopCollection]){
        return CGSizeMake(110*VerticalRatio(), 145*VerticalRatio());
    }else{
        
        return CGSizeMake(106*VerticalRatio(), 130*VerticalRatio());
    }
    
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if ([collectionView isEqual:self.recommendBandsCollection]) {
        return UIEdgeInsetsMake(0,1*VerticalRatio(), 1*VerticalRatio(), 1*VerticalRatio());
    }else if([collectionView isEqual:self.hotGroupShopCollection]){
        return UIEdgeInsetsMake(0,4*VerticalRatio(), 0, 0);
    }else{
        
         return UIEdgeInsetsMake(0,0, 1*VerticalRatio(), 1*VerticalRatio());
    }
   
    
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.recommendBandsCollection]) {
        RecommendCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:bandsCellIdentifer forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor blackColor];
        [cell.bandsImage sd_setImageWithURL:[NSURL URLWithString:_brandSellingArray[indexPath.row][@"mbraIconImagUri"]]];
        return cell;
        
    }else if([collectionView isEqual:self.hotGroupShopCollection]){
        //热门团购
        HotGroupShopCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:hotGroupCellIdentifer forIndexPath:indexPath];
        [cell.goodsImage sd_setImageWithURL:[NSURL URLWithString:_productGroupPurchase[indexPath.row][@"storeImg"]]];
        cell.goodsName.text = _productGroupPurchase[indexPath.row][@"storeName"];
        cell.goodsInfo.text = _productGroupPurchase[indexPath.row][@"mgprName"];
        cell.goodsPrice.text = [NSString stringWithFormat:@"￥%@",_productGroupPurchase[indexPath.row][@"mgpiGourponAmount"]];
        return cell;
    }else{
        HotRecommentCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:hotCellIdentifer forIndexPath:indexPath];
        
        NSString * image = _neGoodsRecommend[indexPath.row][@"appAdertImagUri"];
        if (image.length>0) {
            [cell.goodsImage sd_setImageWithURL:[NSURL URLWithString: image]];
        }else{
            cell.goodsImage.image =[UIImage imageNamed:@"cloth1"];
        }
        cell.goodsPrice.text = [NSString stringWithFormat:@"￥%@",_neGoodsRecommend[indexPath.row][@"mgooPublishPrice"]];
        cell.goodsName.text = _neGoodsRecommend[indexPath.row][@"mgooName"];
        
        return cell;
        
    }
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if ([collectionView isEqual:self.recommendBandsCollection]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        ShopViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Shop"];
        page.storeId = _brandSellingArray[indexPath.row][@"mbraId"];
        [self.navigationController   pushViewController:page animated:YES];

    }else if ([collectionView isEqual:self.hotGroupShopCollection]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        GroupShoppingDetailViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"GroupShoppingDetail"];
        page.groupShoppingId = _productGroupPurchase[indexPath.row][@"mgprId"];
        [self.navigationController   pushViewController:page animated:YES];
    } else{

                UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
                ShoppingProductDetailViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductDetail"];
                page.goodsId = _neGoodsRecommend[indexPath.row][@"mgooId"];
                [self.navigationController   pushViewController:page animated:YES];
    }
    
}


#pragma mark----DYQBannerScrollViewDelegate

-(void)bannerScrollView:(DYQBannerScrollView *)bannerScrollView didSelectItemAtIndex:(NSInteger)index
{
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"PersonCenterStoryboard" bundle:nil];
    WebDetailInfoViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"WebDetailInfo"];
    page.objectId = _bannerArray[index][@"appAdertUrl"];
    page.titleStr = @"详情";
    page.meType = @"4";
    [self.navigationController  pushViewController:page animated:YES];
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    [self.mainScroll.header endRefreshing];
    
    if (tag==SX_kADBannerTag) {
        
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [self.imageArray removeAllObjects];

            for (NSDictionary *data in database[@"result"]) {
                [_bannerArray addObject:data];
                NSString * picture = [Common stringFromData:data[@"appAdertImagUri"]];
                [self.imageArray addObject:picture];
            }
            self.bannerScrollView.imageUrls = self.imageArray;
            self.bannerScrollView.delegate = self;
        }
        
    }else if (tag == SX_SX_queryfincationCount){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSInteger num = [database[@"result"][@"count"]integerValue];
            if (num==0) {
                _noticeNumber.hidden = YES;
            }else{
                _noticeNumber.hidden = NO;
                _noticeNumber.text = [NSString stringWithFormat:@"%@",database[@"result"][@"count"]];
            }
        }
    }else if (tag==SX_QueryMallBrandDataDataTag){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            _brandSellingArray = database[@"result"];
            [_recommendBandsCollection reloadData];
        }
    }else   if (tag==SX_GetGoodsList) {
        
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
         _neGoodsRecommend = database[@"result"][@"pageRecord"];
            NSInteger count = _neGoodsRecommend.count/6;
            NSInteger left = _neGoodsRecommend.count%6;
            if (left>0) {
                count+=1;
            }
            _pageController.numberOfPages = count;
            _pageController.currentPage = 0;
            _hotRecommendCollection.contentSize = CGSizeMake(_hotRecommendCollection.frame.size.width*count, _hotRecommendCollection.frame.size.height);
            _hotRecommendCollection.dataSource  = self;
            _hotRecommendCollection.delegate = self;
            [_hotRecommendCollection reloadData];
        }
    }else if (tag == SX_queryAppPopularGroupPurchaseTag){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            _productGroupPurchase = database[@"result"];
            [self.hotGroupShopCollection reloadData];
        }
    }

}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    [self.mainScroll.header endRefreshing];
    //
    [self dismissWaitDialog];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
